From: Aleksey Kladov Date: Tue, 3 Apr 2018 13:06:56 +0000 (+0300) Subject: Test out-dir edge cases X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~1^2~103^2~1 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=b7976d1e376afb5f7b62d6118978fb090ede4e21;p=cargo.git Test out-dir edge cases --- diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index fe6a5b5f9..52e6cccaf 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -605,9 +605,8 @@ fn link_targets<'a, 'cfg>( destinations.push(dst.display().to_string()); hardlink_or_copy(&src, &dst)?; if let Some(ref path) = export_dir { - //TODO: check if dir if !path.exists() { - fs::create_dir(path)?; + fs::create_dir_all(path)?; } hardlink_or_copy(&src, &path.join(dst.file_name().unwrap()))?; diff --git a/tests/testsuite/out_dir.rs b/tests/testsuite/out_dir.rs index 231f50122..9a241ae26 100644 --- a/tests/testsuite/out_dir.rs +++ b/tests/testsuite/out_dir.rs @@ -1,8 +1,12 @@ -use cargotest::ChannelChanger; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; use std::path::Path; -use std::fs; +use std::fs::{self, File}; +use std::env; +use std::io::Write; + +use hamcrest::assert_that; + +use cargotest::{process, ChannelChanger}; +use cargotest::support::{execs, project}; #[test] fn binary_with_debug() { @@ -195,6 +199,74 @@ fn include_only_the_binary_from_the_current_package() { ); } +#[test] +fn out_dir_is_a_file() { + let p = project("foo") + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + "#, + ) + .file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#) + .build(); + File::create(p.root().join("out")).unwrap(); + + assert_that( + p.cargo("build -Z out-dir --out-dir out") + .masquerade_as_nightly_cargo(), + execs() + .with_status(101) + .with_stderr_contains("[ERROR] failed to link or copy [..]"), + ); +} + +#[test] +fn replaces_artifacts() { + let p = project("foo") + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + "#, + ) + .file("src/main.rs", r#"fn main() { println!("foo") }"#) + .build(); + + assert_that( + p.cargo("build -Z out-dir --out-dir out") + .masquerade_as_nightly_cargo(), + execs().with_status(0), + ); + assert_that( + process(&p.root() + .join(&format!("out/foo{}", env::consts::EXE_SUFFIX))), + execs().with_stdout("foo"), + ); + + fs::File::create(p.root().join("src/main.rs")) + .unwrap() + .write_all(br#"fn main() { println!("bar") }"#) + .unwrap(); + + assert_that( + p.cargo("build -Z out-dir --out-dir out") + .masquerade_as_nightly_cargo(), + execs().with_status(0), + ); + assert_that( + process(&p.root() + .join(&format!("out/foo{}", env::consts::EXE_SUFFIX))), + execs().with_stdout("bar"), + ); +} + fn check_dir_contents( out_dir: &Path, expected_linux: &[&str],